package model;

import java.io.Serializable;

import javax.persistence.*;

import dtos.HotelDTO;
import dtos.PersonalizedTPDTO;
import dtos.PredefinedTPDTO;

import java.util.LinkedList;
import java.util.List;


/**
 * The persistent class for the hotel database table.
 * 
 */
@Entity
@Table(name = "HOTEL")
@NamedQuery(name="Hotel.findAll", query="SELECT h FROM Hotel h")
public class Hotel implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private int hotelID;

	private String arrivalPlace;

	private int classification;

	private int cost;

	private String name;

	private String streetName;

	private int streetNumber;

	//bi-directional many-to-one association to PersonalizedTP
	@OneToMany(mappedBy="hotelBean")
	private List<PersonalizedTP> personalizedTps;

	//bi-directional many-to-one association to PredefinedTP
	@OneToMany(mappedBy="hotelBean")
	private List<PredefinedTP> predefinedTps;

	public Hotel() {
	}
	
public Hotel(HotelDTO hotel){
        
        this.arrivalPlace    = hotel.getArrivalPlace();
        this.name     = hotel.getName();        
        this.classification     = hotel.getClassification();
        this.cost = hotel.getCost();
        this.streetName = hotel.getStreetName();
        this.streetNumber = hotel.getStreetNumber();
    }
	
	public HotelDTO getDTO(){
		HotelDTO h = new HotelDTO();
		h.setArrivalPlace(this.arrivalPlace);
		h.setClassification(this.classification);
		h.setCost(this.cost);
		h.setHotelID(this.hotelID);
		h.setName(this.name);
		//h.setPersonalizedTps(this.getPersonalizedTpsDTO());
		//h.setPredefinedTps(this.getPredefinedTpsDTO());
		h.setStreetName(this.streetName);
		h.setStreetNumber(this.streetNumber);
		return h;
	}

	public boolean isAtPlace(String place){
		return (arrivalPlace.equals(place));

	}
	
	public int getHotelID() {
		return this.hotelID;
	}


	public void setHotelID(int hotelID) {
		this.hotelID = hotelID;
	}
	
	


	public String getArrivalPlace() {
		return this.arrivalPlace;
	}

	public void setArrivalPlace(String arrivalPlace) {
		this.arrivalPlace = arrivalPlace;
	}

	public int getClassification() {
		return this.classification;
	}

	public void setClassification(int classification) {
		this.classification = classification;
	}

	public int getCost() {
		return this.cost;
	}

	public void setCost(int cost) {
		this.cost = cost;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getStreetName() {
		return this.streetName;
	}

	public void setStreetName(String streetName) {
		this.streetName = streetName;
	}

	public int getStreetNumber() {
		return this.streetNumber;
	}

	public void setStreetNumber(int streetNumber) {
		this.streetNumber = streetNumber;
	}

	public List<PersonalizedTP> getPersonalizedTps() {
		return this.personalizedTps;
	}
	
	public List<PersonalizedTPDTO> getPersonalizedTpsDTO() {
		List<PersonalizedTPDTO> res = new LinkedList<PersonalizedTPDTO>();
		for (PersonalizedTP p : this.personalizedTps){
			res.add(p.getDTO());
		}
		return res;
		
	}

	public void setPersonalizedTps(List<PersonalizedTP> personalizedTps) {
		this.personalizedTps = personalizedTps;
	}

	public PersonalizedTP addPersonalizedTp(PersonalizedTP personalizedTp) {
		getPersonalizedTps().add(personalizedTp);
		personalizedTp.setHotelBean(this);

		return personalizedTp;
	}

	public PersonalizedTP removePersonalizedTp(PersonalizedTP personalizedTp) {
		getPersonalizedTps().remove(personalizedTp);
		personalizedTp.setHotelBean(null);

		return personalizedTp;
	}

	public List<PredefinedTP> getPredefinedTps() {
		return this.predefinedTps;
	}
	
	public List<PredefinedTPDTO> getPredefinedTpsDTO() {
		List<PredefinedTPDTO> res = new LinkedList<PredefinedTPDTO>();
		for (PredefinedTP p : this.predefinedTps){
			res.add(p.getDTO());
		}
		return res;
		
	}

	public void setPredefinedTps(List<PredefinedTP> predefinedTps) {
		this.predefinedTps = predefinedTps;
	}

	public PredefinedTP addPredefinedTp(PredefinedTP predefinedTp) {
		getPredefinedTps().add(predefinedTp);
		predefinedTp.setHotelBean(this);

		return predefinedTp;
	}

	public PredefinedTP removePredefinedTp(PredefinedTP predefinedTp) {
		getPredefinedTps().remove(predefinedTp);
		predefinedTp.setHotelBean(null);

		return predefinedTp;
	}

}